package ca.radiologydb.util;

import java.io.*;


/**
 * Provides a way for jsp files and servlets to produce output
 * that conforms to a HTML\CSS form.
 * 
 * @author Jordan Ching, Nicholas Liu
 *
 */
public class Template {
	
	private String template_top_string;
	private String template_bottom_string;
	
	/**
	 * Defines a new Template object.
	 * 
	 * @param absolutepath
	 * @throws IOException
	 */
	public Template (String absolutepath) throws IOException {
		
		try {
			FileInputStream template_stream = new FileInputStream(absolutepath + "Files/template_top.html");
			DataInputStream in = new DataInputStream(template_stream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String str;
			
			template_top_string = "";
			
			while ((str = br.readLine()) != null) {
				template_top_string += str + "\n";
			}
			
			in.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			System.out.println("Error opening template top file.\n");
		}
		
		try {
			FileInputStream template_stream = new FileInputStream(absolutepath + "Files/template_bottom.html");
			DataInputStream in = new DataInputStream(template_stream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String str;
			
			template_bottom_string = "";
			
			while ((str = br.readLine()) != null) {
				template_bottom_string += str + "\n";
			}
			
			in.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			System.out.println("Error opening template bottom file.\n");
		}
		
		
	}
	
	/**
	 * Getter for the top template string.
	 * 
	 * @return	A string containing the top template.
	 */
	public String getTemplateTop() {
		return template_top_string;
	}
	
	/**
	 * Getter for the bottom template string.
	 * 
	 * @return	A string containing the bottom template.
	 */
	public String getTemplateBottom() {
		return template_bottom_string;
	}

}
